<?php
//zend53   
//Decode by www.dephp.cn  QQ 2859470
?>
<?php

defined("IN_ECTOUCH") || exit("Deny Access");
header("Content-Type:text/html;charset=utf-8");
define("APPNAME", "ECTouch");
define("VERSION", "2.10.26");
define("RELEASE", "20160826");
defined("BASE_PATH") || define("BASE_PATH", dirname(__FILE__) . "/");
defined("ROOT_PATH") || define("ROOT_PATH", str_replace("\\", "/", realpath(dirname(__FILE__) . "/../")) . "/");
defined("APP_PATH") || define("APP_PATH", BASE_PATH . "apps/");
defined("ADDONS_PATH") || define("ADDONS_PATH", ROOT_PATH . "plugins/");
defined("DEFAULT_APP") || define("DEFAULT_APP", "default");
defined("DEFAULT_CONTROLLER") || define("DEFAULT_CONTROLLER", "Index");
defined("DEFAULT_ACTION") || define("DEFAULT_ACTION", "index");
require (BASE_PATH . "vendor/autoload.php");
require (BASE_PATH . "base/helpers/function.php");
c(load_file(BASE_PATH . "config/global.php"));
c("APP", load_file(BASE_PATH . "config/app.php"));
c("DB", load_file(ROOT_PATH . "data/config.php"));
date_default_timezone_set(c("DEFAULT_TIMEZONE"));
defined("APP_DEBUG") || define("APP_DEBUG", c("DEBUG"));
defined("IS_ECSHOP") || define("IS_ECSHOP", RUN_ON_ECS);

if (APP_DEBUG) {
	error_reporting(30719 ^ 8);
	$whoops = new Whoops\Run();
	$whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());
	$whoops->register();
}
else {
	@ini_set("display_errors", 0);
	error_reporting(0);
}

spl_autoload_register("autoload");
urlroute();

try {
	defined("__HOST__") || define("__HOST__", get_domain());
	defined("__ROOT__") || define("__ROOT__", rtrim(dirname($_SERVER["SCRIPT_NAME"]), "\/"));
	defined("__URL__") || define("__URL__", __HOST__ . __ROOT__);
	defined("__ADDONS__") || define("__ADDONS__", __ROOT__ . "/plugins");
	defined("__PUBLIC__") || define("__PUBLIC__", __ROOT__ . "/data/assets");
	defined("__ASSETS__") || define("__ASSETS__", __ROOT__ . "/data/assets/" . APP_NAME);

	if (!file_exists(ROOT_PATH . "data/install.lock")) {
		header("Location: ./install/");
		exit();
	}

	$controller = CONTROLLER_NAME . "Controller";
	$action = ACTION_NAME;

	if (!class_exists($controller)) {
		e(APP_NAME . "/" . $controller . ".class.php 控制器类不存在", 404);
	}

	$controller = (class_exists("MY_" . $controller) ? "MY_" . $controller : $controller);
	$obj = new $controller();

	if (!preg_match("/^[A-Za-z](\w)*$/", $action)) {
		e(APP_NAME . "/" . $controller . ".class.php的" . $action . "() 方法不合法", 404);
	}

	if (!method_exists($obj, $action)) {
		e(APP_NAME . "/" . $controller . ".class.php的" . $action . "() 方法不存在", 404);
	}

	$method = new ReflectionMethod($obj, $action);
	if ($method->isPublic() && !$method->isStatic()) {
		$obj->{$action}();
	}
	else {
		e(APP_NAME . "/" . $controller . ".class.php的" . $action . "() 方法没有访问权限", 404);
	}
}
catch (Exception $e) {
	e($e->getMessage(), $e->getCode());
}

?>
